<%--
  Created by IntelliJ IDEA.
  User: 10161
  Date: 2018/12/27
  Time: 16:47
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>新闻类别</title>
    <meta charset="UTF-8">

    <script type="text/javascript" src="${pageContext.request.contextPath}/statics/js/jquery-1.11.0.js"></script>
    <script type="text/javascript">
        function deleteNewsType(id) {
            $.get("/newstype/dodelete",{id:id},function (result) {
                if (!confirm("删除类别会删除所有其子类，你确定要删除嘛！")){
                    return ;
                }
                if(result=="1"){
                    alert("删除成功");
                }else {
                    alert("删除失败");

                }
                window.location= window.location;
            });
        }

        $(function () {
            $("#cbAll").click(function () {
                $("input[name='cbItem']").prop("checked", $("#cbAll").prop("checked"));
            });
        });
        function deleteAllNewsType () {
            if (!confirm("删除类别会删除所有其子类，你确定要删除嘛！")){
                return ;
            }
            var ids ="-1";
            $("input[name='cbItem']").each(function () {
                if(this.checked){
                    var id= $(this).val();
                    ids+=","+id;
                }
            });
            $.get("${pageContext.request.contextPath }/newstype/dodeleteall",{ids:ids},function (result) {
                if(result=="1"){
                    alert("批量删除成功");
                }else {
                    alert("批量删除失败");
                }
                window.location= window.location;
            });
        }
    </script>
</head>
<body>
<form action="${pageContext.request.contextPath}/newstype/list" method="post">
<table>
    <tr>
        <td>类别名称:<input type="text" name="typeName" value="${newsType.typeName}"/> </td>
        <td>父类别:<select name="parentId">
            <option value="0">==不限==</option>
            <c:forEach var="item" items="${plist}">
                <option <c:if test="${item.id==newsType.parentId}">selected="selected"</c:if>
                        value="${item.id}">${item.typeName}</option>
            </c:forEach>
        </select> </td>
        <td>
            <input type="submit" value="搜索">&nbsp;
            <a href="javascript:void(0)" onclick="deleteAllNewsType()">批量删除</a>
        </td>
        <td>类别名称</td>
    </tr>
</table>
</form>
<table>
    <tr>
        <td><input type="checkbox" id="cbAll"/>ID</td>
        <td>类别名称</td>
        <td>父类别</td>
        <td>创建日期</td>
        <td>操作</td>
    </tr>
    <c:forEach items="${list}" var="li">
        <tr>
            <td><input type="checkbox" name="cbItem" value="${li.id}"/>${li.id}</td>
            <td>${li.typeName}</td>
            <td>${li.parentName}</td>
            <td>${li.createDate}</td>
            <td><a href="${pageContext.request.contextPath}/newstype/update?id=${li.id}">修改</a>
                <a href="javascript:void(0)" onclick="deleteNewsType(${li.id});">删除</a></td>
        </tr>
    </c:forEach>
</table>
<p>共${pageTool.totalRecordCount}条数据，当前第${pageTool.currPageNo}/${pageTool.pageCount}页，每页${pageTool.pageSize}条，


    <a href="${pageContext.request.contextPath }/newstype/list?typeName=${newsType.typeName}&parentId
        =${newsType.parentId}&currPageNo=1">首页</a>

    <a href="${pageContext.request.contextPath }/newstype/list?typeName=${newsType.typeName}&parentId
        =${newsType.parentId}&currPageNo=${pageTool.currPageNo-1}">前一页</a>

    <c:forEach var="prePage" items="${prePages}">
        <a href="${pageContext.request.contextPath }/newstype/list?typeName=${newsType.typeName}&parentId
        =${newsType.parentId}&currPageNo=${pageTool.currPageNo-1}">${prePage}</a>
    </c:forEach>

    <b>${pageTool.currPageNo}</b>

    <c:forEach var="nextPage" items="${nextPages}">
        <a href="${pageContext.request.contextPath }/newstype/list?typeName=${newsType.typeName}&parentId
        =${newsType.parentId}&currPageNo=${pageTool.currPageNo+1}">${nextPage}</a>
    </c:forEach>


    <a href="${pageContext.request.contextPath }/newstype/list?typeName=${newsType.typeName}&parentId
        =${newsType.parentId}&currPageNo=${pageTool.currPageNo+1}">下一页</a>

    <a href="${pageContext.request.contextPath }/newstype/list?typeName=${newsType.typeName}&parentId
        =${newsType.parentId}&currPageNo=${pageTool.pageCount}">末页</a>

</p>

</body>
</html>
